package com.mystyle.le.weekproject.asynctaks;

import android.content.Context;
import android.os.AsyncTask;

import com.mystyle.le.weekproject.intentfactbackcall.MyCallBack;
import com.mystyle.le.weekproject.utils.DownData;

/**
 * 资讯头条ListView的下载任务
 * Created by le on 2016/10/10.
 */
public class HeadListAsyncTaks extends AsyncTask<String,Void,String> {
    private MyCallBack.HeadListBack headListBack;
    private Context context;

    public HeadListAsyncTaks(MyCallBack.HeadListBack headListBack, Context context) {
        this.headListBack = headListBack;
        this.context = context;
    }

    @Override
    protected String doInBackground(String... params) {
        boolean netWorkConn = DownData.isNetWorkConn(context);
        if (netWorkConn){
            String param = params[0];
            byte[] bytes = DownData.downData(param);
            if (bytes!=null&&bytes.length>0){
                String path = new String(bytes,0,bytes.length);
                return path;
            }
        }
       return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        if (s!=null){
            headListBack.sendBack(s);
        }
    }
}
